﻿<button value="开始" id="show"> 开始</button>
<script id="addinfo" type="text/html">
    <form class="layui-form" action="" lay-filter="addinfos">

        <div class="layui-form-item">

            <div class="layui-inline">
                <label class="layui-form-label">背景图片</label>
                <div class="layui-input-block">
                    <img id="imgs" style="width:100px;height:100px" />
                    <input type="text" id="Pic" name="Pic" value="" />
                    <button type="button" id="j_upload_img_btn" class="layui-btn layui-btn-radius">选择</button>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">附件</label>
                <div class="layui-input-block">

                    <input type="text" id="file" name="file" />
                    <button type="button" id="j_upload_file_btn" class="layui-btn layui-btn-radius">选择</button>
                </div>
            </div>
        </div>
    </form>
</script>

<!-- 加载编辑器的容器 -->
<link href="/Common/layim/dist/css/layui.css" rel="stylesheet" />
<textarea id="uploadEditor" style="display: none;"></textarea>
<script src="/Common/layim/dist/layui.all.js"></script>
<script src="/Common/ueditor/ueditor.config.js"></script>
<script src="/Common/ueditor/ueditor.all.js"></script>
<!--<script src="/Common/ueditor/ueditor.all.min.js"></script>-->
<script src="/Common/ueditor/lang/zh-cn/zh-cn.js"></script>

<script>
    layui.config({
        base: '/Common/layim/layui_exts/' //指定 插件 路径
        , version: '1.0.0-beta'
    }).use(['form', 'layer', 'laydate', 'table', 'common'], function () {
        $ = layui.$; layer = layui.layer, common = layui.common;
        common.islogin();
        // 实例化编辑器，这里注意配置项隐藏编辑器并禁用默认的基础功能。
        var uploadEditor = UE.getEditor("uploadEditor", {
            isShow: false,
            focus: false,
            enableAutoSave: false,
            autoSyncData: false,
            autoFloatEnabled: false,
            wordCount: false,
            sourceEditor: null,
            scaleEnabled: true,
            toolbars: [["insertimage", "attachment"]]
        });

        // 监听多图上传和上传附件组件的插入动作
        uploadEditor.ready(function () {
            uploadEditor.addListener("beforeInsertImage", _beforeInsertImage);
            uploadEditor.addListener("afterUpfile", _afterUpfile);
        });

        // 自定义按钮绑定触发多图上传和上传附件对话框事件

        document.getElementById('j_upload_img_btn').onclick = function () {
            var dialog = uploadEditor.getDialog("insertimage");
            dialog.title = '多图上传';
            dialog.render();
            dialog.open();
            dialog.oncancel = function (s, f) {
                layer.restore(uplay);
                console.log(f);
            };
            layer.min(uplay);
        };
        document.getElementById('show').onclick = function () {
            uplay = layer.open({
                type: 1, title: "上传",
                area: ['650px', '490px'], shade: 0,
                fixed: false, //不固定
                maxmin: true,
                content: $("#addinfo")[0].innerHTML, success: function (layero) {

                }, cancel: function () {


                }
            });
        };

        document.getElementById('j_upload_file_btn').onclick = function () {
            var dialog = uploadEditor.getDialog("attachment");
            dialog.title = '附件上传';
            dialog.render();
            dialog.open();
            dialog.oncancel = function (s, f) {
                layer.restore(uplay);
                console.log(f);
            };
            layer.min(uplay);
        };

        // 多图上传动作
        function _afterUpfile(t, result) {
            console.log(222);
            var arr_v = new Array();
            $(result).each(function () {
                arr_v.push(this.url);

            });
            arr_v.join(',');
            $("#file").val(arr_v);
            layer.restore(uplay);
        }
        // 多图上传动作
        function _beforeInsertImage(t, result) {
            var arr_v = new Array();
            $(result).each(function () {
                arr_v.push(this.src);

            });
            arr_v.join(',');
            $("#Pic").val(arr_v);
            layer.restore(uplay);
        }
    })
</script>